package cn.fl.repay.service.impl;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.commons.enums.GlobalApiCode;
import cn.fl.commons.result.ResponseData;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.mcr.api.IMcrBillDApiService;
import cn.fl.mcr.api.IMcrBillMApiService;
import cn.fl.mcr.condition.McrBillDQC;
import cn.fl.mcr.condition.McrBillMQC;
import cn.fl.mcr.dto.McrBillDDTO;
import cn.fl.mcr.dto.McrBillMDTO;
import cn.fl.repay.condition.InsOfflineRepayDtlQueryCondition;
import cn.fl.repay.constant.RepayConstant;
import cn.fl.repay.dto.InsOfflineRepayDtlDTO;
import cn.fl.repay.service.IInsOfflineRepayDtlApiService;
import cn.fl.repay.service.IInsOfflineRepayDtlService;
import cn.fl.repay.transform.InsOfflineRepayDtlVOTransform;
import cn.fl.repay.utils.BigDecimalUtils;
import cn.fl.repay.vo.InsOfflineRepayDtlVO;
import cn.fl.repay.vo.YilianRepayTrialVO;
import cn.lionbridgecapital.loan.service.api.IYiLlionApiService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.shiqiao.fl.repay.bill.dto.BillInfoDTO;
import com.shiqiao.fl.repay.bill.dto.BillItemDTO;
import com.shiqiao.fl.repay.bill.facade.IRepayBillApiService;
import com.shiqiao.fl.repay.bill.request.QueryPeriodBillInfoParam;
import com.shiqiao.fl.repay.order.constant.CapRepayOrderConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @Description: 线下还款申请明细表 客户端服务层接口实现
 * 业务层方法名称前缀：
 * 新增：add*
 * 删除：remove*
 * 修改：modify*
 * 批量：batch*
 * 查询对象：select* get*
 * 查询集合：search*
 */
@Service
public class InsOfflineRepayDtlServiceImpl implements IInsOfflineRepayDtlService {

	/**
     * 日志
     */
    @SuppressWarnings("unused")
    private static final Logger logger = LoggerFactory.getLogger(InsOfflineRepayDtlServiceImpl.class);
	
	/**
	 * TODO 自定义 API 暴露服务
	 */
	@Autowired
	private IInsOfflineRepayDtlApiService insOfflineRepayDtlApiService;
	/**
     * 数据字典服务
     */
    @Autowired
    private ISysDictionaryApiService sysDictionaryApiService;
	@Autowired
	private IMcrBillMApiService mcrBillMApiService;
	@Autowired
	private IMcrBillDApiService mcrBillDApiService;
	@Autowired
	private IYiLlionApiService yiLlionApiService;

	@Resource
	private IRepayBillApiService repayBillApiService;

	@Override
	public InsOfflineRepayDtlVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)) return null;
		InsOfflineRepayDtlDTO dto = this.insOfflineRepayDtlApiService.selectInsOfflineRepayDtlById(id);
		return InsOfflineRepayDtlVOTransform.toVO(dto);
	}

	@Override
	public Long add(InsOfflineRepayDtlVO entity) throws BaseException{
		if(null == entity) return null;
		return this.insOfflineRepayDtlApiService.addInsOfflineRepayDtl(InsOfflineRepayDtlVOTransform.toDTO(entity));
	}

	@Override
	public void batchAdd(List<InsOfflineRepayDtlVO> list) throws BaseException {
		if(CollectionUtils.isEmpty(list)) return;
		this.insOfflineRepayDtlApiService.batchAddInsOfflineRepayDtl(InsOfflineRepayDtlVOTransform.toDTOList(list));
	}

	@Override
	public boolean removeByIds(List<Long> ids) throws BaseException{
		if(CollectionUtils.isEmpty(ids)) return false;
		return this.insOfflineRepayDtlApiService.removeInsOfflineRepayDtlByIds(ids, CurrentThreadContext.getCurrentUserId());
	}

	@Override
	public boolean modify(InsOfflineRepayDtlVO entity) throws BaseException{
		if(null == entity) return false;
		return this.insOfflineRepayDtlApiService.modifyInsOfflineRepayDtl(InsOfflineRepayDtlVOTransform.toDTO(entity));
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
        InsOfflineRepayDtlQueryCondition condition=null;
        if(null == page) {
            page = new Pager();
            page.setCondition(new InsOfflineRepayDtlQueryCondition());
        }
		condition=(InsOfflineRepayDtlQueryCondition)page.getCondition();
        condition.setSysCd(CurrentThreadContext.getCurrentSysCd());//当前系统代码
        condition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());//当前机构代码
        condition.setUsrId(CurrentThreadContext.getCurrentUserId());//当前用户ID
		page=this.insOfflineRepayDtlApiService.searchInsOfflineRepayDtlListPage(page);
		if(CollectionUtils.isNotEmpty(page.getResultList())){
            List<InsOfflineRepayDtlVO> voList= InsOfflineRepayDtlVOTransform.toVOList((List<InsOfflineRepayDtlDTO>)page.getResultList());
            //this.setDictData(voList);
            page.setResultList(voList);
        }
        return page;
	}
	
	@Override
	public List<InsOfflineRepayDtlVO> searchList(InsOfflineRepayDtlQueryCondition condition) throws BaseException{
		if(null == condition) condition=new InsOfflineRepayDtlQueryCondition();
		condition.setSysCd(CurrentThreadContext.getCurrentSysCd());//当前系统代码
		condition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());//当前机构代码
		condition.setUsrId(CurrentThreadContext.getCurrentUserId());//当前用户ID
		List<InsOfflineRepayDtlVO> voList= InsOfflineRepayDtlVOTransform.toVOList(this.insOfflineRepayDtlApiService.searchInsOfflineRepayDtlList(condition));
		this.setDictData(voList);
		return voList;
	}
	
    /**
     * 添加数据字典名称
     * @param voList
     */
	public void setDictData(List<InsOfflineRepayDtlVO> voList){
		if(CollectionUtils.isEmpty(voList)) return;
		/*Map<String, String> _CdMap = this.sysDictionaryApiService.searchGroupToMap(sysCd, orgCd, InsOfflineRepayDtlConstant.CODE_CD);
		for(InsOfflineRepayDtlVO vo:voList){
			if (_CdMap != null && _CdMap.containsKey(vo.getCd())) {
            	vo.setCdNm(_CdMap.get(vo.getCd()));
        	}	
		}*/
	}

	@Override
	public List<InsOfflineRepayDtlVO> getTrustSettleRepayDtl(String crCntNo, String actPayDt) {
		// 查询结清金额
		McrBillMDTO mcrBillMDTO = getSettleBill(crCntNo, actPayDt);

		// 查询账单明细
		McrBillDQC mcrBillDQC = new McrBillDQC();
		mcrBillDQC.setBillId(mcrBillMDTO.getId());
		BaseLogUtils.info(logger, "getTrustSettleRepayDtl", "mcrBillDApiService.searchMcrBillDList.REQUEST:" + JSONObject.toJSONString(mcrBillDQC), CurrentThreadContext.getCurrentUserName());
		List<McrBillDDTO> billDDTOList = mcrBillDApiService.searchMcrBillDList(mcrBillDQC);
		BaseLogUtils.info(logger, "getTrustSettleRepayDtl", "mcrBillDApiService.searchMcrBillDList.RESPONSE:" + JSONObject.toJSONString(billDDTOList), CurrentThreadContext.getCurrentUserName());
		if (org.springframework.util.CollectionUtils.isEmpty(billDDTOList)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "查询mcrbillD返回数据为空.");
		}
		Date actPayDate = DateUtils.formatStringToDate(actPayDt, DateUtils.YYYY_MM_DD);
		McrBillDDTO billDDTO = billDDTOList.stream().sorted(Comparator.comparing(McrBillDDTO::getPayPd))
				.filter(p -> p.getPayDt().after(actPayDate)).findFirst()
				.orElseThrow(() ->new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "最后一期还款日之后，不能发起提前结清."));

		// 组装数据
		List<InsOfflineRepayDtlVO> repayDtlVOList = new ArrayList<>();
		InsOfflineRepayDtlVO repayDtlVO = new InsOfflineRepayDtlVO();
		repayDtlVO.setPayPd(billDDTO.getPayPd());
		repayDtlVO.setCapAmt(mcrBillMDTO.getArCapAmt());
		repayDtlVO.setIntrAmt(mcrBillMDTO.getArIntrAmt());
		repayDtlVO.setPntAmt(mcrBillMDTO.getArFineAmt());
		repayDtlVO.setDamAmt(mcrBillMDTO.getArDamAmt());
		repayDtlVO.setGrtAmt(0L);
		repayDtlVO.setOvdGrtAmt(0L);
		repayDtlVO.setRepayState("");
		repayDtlVOList.add(repayDtlVO);
		return repayDtlVOList;
	}

	@Override
	public List<InsOfflineRepayDtlVO> getYiLianBankSettleRepayDtl(String crCntNo, String actPayDt) {
		McrBillMDTO mcrBillMDTO = getSettleBill(crCntNo, actPayDt);
		// 组装数据
		List<InsOfflineRepayDtlVO> repayDtlVOList = new ArrayList<>();
		InsOfflineRepayDtlVO repayDtlVO = new InsOfflineRepayDtlVO();
//		repayDtlVO.setPayPd(billDDTO.getPayPd());
		repayDtlVO.setCapAmt(mcrBillMDTO.getArCapAmt());
		repayDtlVO.setIntrAmt(mcrBillMDTO.getArIntrAmt());
		repayDtlVO.setPntAmt(mcrBillMDTO.getArFineAmt());
		repayDtlVO.setDamAmt(mcrBillMDTO.getArDamAmt());
		repayDtlVO.setGrtAmt(mcrBillMDTO.getPayFee());
		repayDtlVO.setOvdGrtAmt(mcrBillMDTO.getPayOverdueFee());
		repayDtlVO.setRepayState("");
		repayDtlVOList.add(repayDtlVO);
		return repayDtlVOList;
	}

	@Override
	public List<InsOfflineRepayDtlVO> getYiLianBankStageRepayDtl(String crCntNo, String actPayDt) {
		List<InsOfflineRepayDtlVO> repayDtlVOList = new ArrayList<>();
		YilianRepayTrialVO repayTrialVO;

		repayTrialVO = this.getRepayTrial(crCntNo, actPayDt.replace("-", "/"));
		List<YilianRepayTrialVO.RepayTrialResult> list = repayTrialVO.getData();
		if (!org.springframework.util.CollectionUtils.isEmpty(list)) {
			for (YilianRepayTrialVO.RepayTrialResult result : list) {
				// 已还的不显示
				if (result.getRepay_state().equals(RepayConstant.REPAY_STATE_REPAID)) {
					continue;
				}
				InsOfflineRepayDtlVO repayDtlVO = new InsOfflineRepayDtlVO();
				repayDtlVO.setPayPd(result.getRepay_period());
				repayDtlVO.setCapAmt(BigDecimalUtils.convertYuanToFen(result.getRepay_principal()));
				repayDtlVO.setIntrAmt(BigDecimalUtils.convertYuanToFen(result.getRepay_interest()));
				repayDtlVO.setPntAmt(BigDecimalUtils.convertYuanToFen(result.getRepay_overdue_interest()));
				repayDtlVO.setGrtAmt(BigDecimalUtils.convertYuanToFen(result.getRepay_fee()));
				repayDtlVO.setOvdGrtAmt(BigDecimalUtils.convertYuanToFen(result.getRepay_overdue_fee()));
				repayDtlVO.setRepayState(result.getRepay_state());
				repayDtlVOList.add(repayDtlVO);
			}
		}
		return repayDtlVOList;
	}

	private McrBillMDTO getSettleBill(String crCntNo, String actPayDt){
		// 查询结清金额
		McrBillMQC mcrBillMQC = new McrBillMQC();
		mcrBillMQC.setCrCntNo(crCntNo);
		mcrBillMQC.setSettleDate(DateUtils.formatStringToDate(actPayDt, DateUtils.YYYY_MM_DD));
		BaseLogUtils.info(logger, "queryReplayPlan", "mcrBillMApiService.searchCstSettleBillList.REQUEST:" + JSONObject.toJSONString(mcrBillMQC), CurrentThreadContext.getCurrentUserName());
		List<McrBillMDTO> mcrBillMDTOList = mcrBillMApiService.searchCstSettleBillList(mcrBillMQC);
		BaseLogUtils.info(logger, "queryReplayPlan", "mcrBillMApiService.searchCstSettleBillList.RESPONSE:" + JSONObject.toJSONString(mcrBillMDTOList), CurrentThreadContext.getCurrentUserName());
		if (CollectionUtils.isEmpty(mcrBillMDTOList)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "查询结清信息返回数据为空.");
		}
		return mcrBillMDTOList.get(0);
	}

	public YilianRepayTrialVO getRepayTrial(String crCntNo, String actPayDt) {
		BaseLogUtils.info(logger, "getRepayTrial", "yiLlionApiService.repayTrialToYL.REQUEST: crCntNo:" + crCntNo,",actPayDt:" + actPayDt +"."+ CurrentThreadContext.getCurrentUserName());
		DataResultDTO dataResultDTO = yiLlionApiService.repayTrialToYL(crCntNo, actPayDt);
		BaseLogUtils.info(logger, "getRepayTrial", "yiLlionApiService.repayTrialToYL.RESPONSE:" + JSONObject.toJSONString(dataResultDTO), CurrentThreadContext.getCurrentUserName());
		if (dataResultDTO.getSuccess() == 0 || dataResultDTO.getData() == null) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "调用亿联获取还款试算失败.");
		}
		YilianRepayTrialVO repayTrialVO = null;
		try {
			repayTrialVO = JSON.parseObject((String) dataResultDTO.getData(), YilianRepayTrialVO.class);
		} catch (Exception e) {
			BaseLogUtils.newLogger("解析还款试算结果失败").setKeys("getRepayTrial", CurrentThreadContext.getCurrentUserName()).setThrowable(e).error(LogExceptionEnum.API_CODE_0102);
		}
		if (repayTrialVO == null) {
//            List<YilianRepayTrialVO.RepayTrialResult> list = repayTrialVO.getData();
//            if (CollectionUtils.isEmpty(list)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "调用亿联获取还款计划明细失败.");
//            }
		}
		return repayTrialVO;
	}

	@Override
	public List<InsOfflineRepayDtlVO> getLaHaiBankSettleRepayDtl(String crCntNo, String actPayDt) {
		McrBillMDTO mcrBillMDTO = getSettleBill(crCntNo, actPayDt);
		Long capAmt = mcrBillMDTO.getArCapAmt();
		Long intrAmt = mcrBillMDTO.getArIntrAmt();
		Long fineAmt = mcrBillMDTO.getArFineAmt();
		Long payFee = mcrBillMDTO.getPayFee();
		Long overdueFee = mcrBillMDTO.getPayOverdueFee();
		// 时间转账当天应还金额
		long totalAmt = capAmt + intrAmt + fineAmt + payFee + overdueFee;

		String currentDateStr = DateUtils.getCurrentDateStr(DateUtils.YYYY_MM_DD);
		McrBillMDTO todayMcrBillMDTO = mcrBillMDTO;
		if (!actPayDt.equals(currentDateStr)) {
			todayMcrBillMDTO = getSettleBill(crCntNo, currentDateStr);
		}
		// 组装数据
		List<InsOfflineRepayDtlVO> repayDtlVOList = new ArrayList<>();
		Long todayCapAmt = todayMcrBillMDTO.getArCapAmt();
		Long todayIntrAmt = todayMcrBillMDTO.getArIntrAmt();
		Long todayFineAmt = todayMcrBillMDTO.getArFineAmt();
		Long todayOverdueFee = todayMcrBillMDTO.getPayOverdueFee();

		InsOfflineRepayDtlVO repayDtlVO = new InsOfflineRepayDtlVO();
		repayDtlVO.setCapAmt(todayCapAmt);
		repayDtlVO.setIntrAmt(todayIntrAmt);
		repayDtlVO.setPntAmt(todayFineAmt);
		repayDtlVO.setDamAmt(0L);
		long surplus = totalAmt - (todayCapAmt + todayIntrAmt +todayFineAmt);
		if (surplus <= 0) {
			repayDtlVO.setOvdGrtAmt(surplus);
			repayDtlVO.setGrtAmt(0L);
		}else {
			if (surplus <= todayOverdueFee) {
				repayDtlVO.setOvdGrtAmt(surplus);
				repayDtlVO.setGrtAmt(0L);
			}else {
				repayDtlVO.setOvdGrtAmt(todayOverdueFee);
				repayDtlVO.setGrtAmt(surplus- todayOverdueFee);
			}
		}
		repayDtlVO.setRepayState("");
		repayDtlVOList.add(repayDtlVO);
		return repayDtlVOList;
	}

	@Override
	public List<InsOfflineRepayDtlVO> getLaHaiBankStageRepayDtl(String crCntNo, String actPayDt) {
		McrBillMQC billMQC = new McrBillMQC();
		billMQC.setCrCntNo(crCntNo);
		BaseLogUtils.info(logger, "queryReplayPlan", "mcrBillMApiService.searchMcrBillMDTOList.REQUEST:" + JSONObject.toJSONString(billMQC), CurrentThreadContext.getCurrentUserName());
		List<McrBillMDTO> billMDTOList = mcrBillMApiService.searchMcrBillMDTOList(billMQC);
		BaseLogUtils.info(logger, "queryReplayPlan", "mcrBillMApiService.searchMcrBillMDTOList.RESPONSE:" + JSONObject.toJSONString(billMDTOList), CurrentThreadContext.getCurrentUserName());
		if (org.springframework.util.CollectionUtils.isEmpty(billMDTOList)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "小贷账单不存在.");
		}
		McrBillMDTO mcrBillMDTO = billMDTOList.get(0);
		Long cstId = mcrBillMDTO.getCstId();
		Long billId = mcrBillMDTO.getId();

		// 时间转账当天应还金额
		Date payDt = DateUtils.formatStringToDate(actPayDt, DateUtils.YYYY_MM_DD);
		List<BillItemDTO> billItemList = getBillItemList(cstId, billId, payDt);
		long totalAmt = billItemList.stream().mapToLong(BillItemDTO::getArAmt).sum();

		Date currentDate = DateUtils.getCurrentDate(DateUtils.YYYY_MM_DD);
		List<BillItemDTO> todayBillItemList = billItemList;
		if (!currentDate.equals(payDt)) {
			todayBillItemList = getBillItemList(cstId, billId, currentDate);
		}
		List<BillItemDTO> lhItemList = todayBillItemList.stream()
				.filter(item -> "S03".equals(item.getFeeTypCd())
						|| "S02".equals(item.getFeeTypCd())
						|| "S05".equals(item.getFeeTypCd()))
				.collect(Collectors.toList());
		long lhTotalAmt = lhItemList.stream().mapToLong(BillItemDTO::getArAmt).sum();
		long surplus = totalAmt - lhTotalAmt;

		List<BillItemDTO> todayOvdPayFeeList = todayBillItemList.stream()
				.filter(item -> "S17".equals(item.getFeeTypCd()))
				.collect(Collectors.toList());
		if (CollectionUtils.isNotEmpty(todayOvdPayFeeList)) {
			todayOvdPayFeeList.sort(Comparator.comparing(BillItemDTO::getPayPd));
			for (BillItemDTO billItemDTO : todayOvdPayFeeList) {
				if (surplus <= 0) {
					billItemDTO.setArAmt(surplus);
					surplus = 0L;
				}else{
					Long arAmt = billItemDTO.getArAmt();
					if (surplus <= arAmt) {
						billItemDTO.setArAmt(surplus);
					}
					surplus = surplus - billItemDTO.getArAmt();
				}
			}
		}

		List<BillItemDTO> todayPayFeeList = todayBillItemList.stream()
				.filter(item -> "S16".equals(item.getFeeTypCd()))
				.collect(Collectors.toList());
		if (CollectionUtils.isNotEmpty(todayPayFeeList)) {
			todayPayFeeList.sort(Comparator.comparing(BillItemDTO::getPayPd));
			for (BillItemDTO billItemDTO : todayPayFeeList) {
				if (surplus <= 0) {
					billItemDTO.setArAmt(surplus);
					surplus = 0L;
				}else{
					Long arAmt = billItemDTO.getArAmt();
					if (surplus <= arAmt) {
						billItemDTO.setArAmt(surplus);
					}
					surplus = surplus - billItemDTO.getArAmt();
				}
			}
		}

		Map<Integer, List<BillItemDTO>> pdToItemListMap =
				todayBillItemList.stream().collect(Collectors.groupingBy(BillItemDTO::getPayPd));
		List<InsOfflineRepayDtlVO> repayDtlVOList = new ArrayList<>();
		pdToItemListMap.forEach((payPd, itemList)->{
			InsOfflineRepayDtlVO repayDtlVO = new InsOfflineRepayDtlVO();
			repayDtlVO.setCapAmt(0L);
			repayDtlVO.setIntrAmt(0L);
			repayDtlVO.setPntAmt(0L);
			repayDtlVO.setGrtAmt(0L);
			repayDtlVO.setOvdGrtAmt(0L);
			repayDtlVO.setPayPd(payPd.longValue());
			for (BillItemDTO item : itemList) {
				if ("S03".equals(item.getFeeTypCd())) {
					repayDtlVO.setCapAmt(item.getArAmt());
					if (item.getPayDt().before(currentDate)) {
						repayDtlVO.setRepayState(RepayConstant.REPAY_STATE_OVERDUE);
					}else{
						repayDtlVO.setRepayState(RepayConstant.REPAY_STATE_NORMAL);
					}

				}else if ("S02".equals(item.getFeeTypCd())) {
					repayDtlVO.setIntrAmt(item.getArAmt());
				}else if ("S05".equals(item.getFeeTypCd())) {
					repayDtlVO.setPntAmt(item.getArAmt());
				}else if ("S16".equals(item.getFeeTypCd())) {
					repayDtlVO.setGrtAmt(item.getArAmt());
				}else if ("S17".equals(item.getFeeTypCd())) {
					repayDtlVO.setOvdGrtAmt(item.getArAmt());
				}

			}
			repayDtlVOList.add(repayDtlVO);
		});
		return repayDtlVOList;
	}

	private List<BillItemDTO> getBillItemList(Long cstId, Long billId, Date payDt){
		QueryPeriodBillInfoParam queryBillParam = new QueryPeriodBillInfoParam();
		queryBillParam.setQueryCmd(QueryPeriodBillInfoParam.QueryCmd.QUERY_BY_CST_ID);
		queryBillParam.setQueryChannel(QueryPeriodBillInfoParam.QueryChannel.APP);
		queryBillParam.setBusinessLine(CapRepayOrderConstant.CODE_ORDER_BUSINESS_OPERATING);
		queryBillParam.setQueryTime(payDt);
		queryBillParam.setCstId(cstId);
		queryBillParam.setBillIdList(Lists.newArrayList(billId));
		ResponseData<List<BillInfoDTO>> listResponseData = repayBillApiService.queryPeriodBillList(queryBillParam);
		if (!listResponseData.isSuccess() || CollectionUtils.isEmpty(listResponseData.getData())) {
			BaseLogUtils.newLogger("查询账单信息异常：{}", JSON.toJSONString(queryBillParam))
					.error(LogExceptionEnum.COMMON_CODE_0001);
			throw new BaseException(GlobalApiCode.BUSINESS_ERROR.getApiCode(), "账单信息错误");
		}
		BillInfoDTO periodBillInfo = listResponseData.getData().get(0);
		if (null == periodBillInfo || !Integer.valueOf(1).equals(periodBillInfo.getCanRepay())
				|| CollectionUtils.isEmpty(periodBillInfo.getBillItems())) {
			BaseLogUtils.newLogger("查询账单信息异常：{}", JSON.toJSONString(periodBillInfo))
					.error(LogExceptionEnum.COMMON_CODE_0001);
			throw new BaseException(GlobalApiCode.BUSINESS_ERROR.getApiCode(), "账单信息错误");
		}
		return periodBillInfo.getBillItems();
	}
}
